
cd "XXX"  /*This directory has to be changed to the one where the data and do-file are saved*/

use "Dataset_Salience", clear

log using "Salience.log", replace

************************************
**Data description and preperation** 
************************************

/*Variables:

username: randomly generated to participants and send to them by mail so they could log on website for experiment
  
password: randomly generated to participants and send to them by mail so they could log on website for experiment

group: a group number automatically allocated to each participant indicating the group that the participants had in the experiment. Group numbers are only relevant in strategic games where it is important to identify participants that were linked together. The group number is not used in the individual decision making situation we have here in the analysis.

screen: the number of the last opened screen of experiment

role: a number indicating the role that the particpants had in the experiment. All have the same number due to individual nature of decision. 

completed: True/False. This is "TRUE" when the particpant has completed the whole experiment

control1: answer of control question 1

control2: answer of control question 2

order: this indicates the sequence in which the individual decision situations were shown. We used a balanced design with all possible sequences

round1-round4: amount bet on risky lottery in each round

random1-random2: randomly generated number to determine payouts

paymentround: round that was paid out

paymentstate: realized state of the world (good or bad) to determine payoffs  

payoff: the payoff in DKK*/

drop if screen<10  /*The reported numbers are based on the participants that completed the full experiment. That is particpats that finish screen 10 of the experiment */

/* In the following we use the variable round1-round4 in the creation of the treatment variables alpha1-alpha4.

alpha1-alpha4: as round1 with order 0 is different from round1 with order 1 etc, we need to create the treatment variables alpha1-alpha4 that respectively indicate the amount bet on the risky lottery by every participant at the different treatment levels 0,1,2,3  */

quietly {
	generate alpha1=0

	replace alpha1=round1 if order==0 
	replace alpha1=round1 if order==1  
	replace alpha1=round1 if order==2 
	replace alpha1=round1 if order==3  
	replace alpha1=round1 if order==4 
	replace alpha1=round1 if order==5  
	replace alpha1=round2 if order==6 
	replace alpha1=round2 if order==7  
	replace alpha1=round3 if order==8 
	replace alpha1=round4 if order==9  
	replace alpha1=round3 if order==10 
	replace alpha1=round4 if order==11
	replace alpha1=round2 if order==12 
	replace alpha1=round2 if order==13  
	replace alpha1=round3 if order==14 
	replace alpha1=round4 if order==15  
	replace alpha1=round3 if order==16 
	replace alpha1=round4 if order==17  
	replace alpha1=round2 if order==18 
	replace alpha1=round2 if order==19  
	replace alpha1=round3 if order==20 
	replace alpha1=round4 if order==21  
	replace alpha1=round3 if order==22 
	replace alpha1=round4 if order==23  

	generate alpha2=0

	replace alpha2=round2 if order==0 
	replace alpha2=round2 if order==1  
	replace alpha2=round3 if order==2 
	replace alpha2=round4 if order==3  
	replace alpha2=round3 if order==4 
	replace alpha2=round4 if order==5  
	replace alpha2=round1 if order==6 
	replace alpha2=round1 if order==7  
	replace alpha2=round1 if order==8 
	replace alpha2=round1 if order==9  
	replace alpha2=round1 if order==10 
	replace alpha2=round1 if order==11
	replace alpha2=round3 if order==12 
	replace alpha2=round4 if order==13  
	replace alpha2=round2 if order==14 
	replace alpha2=round2 if order==15  
	replace alpha2=round4 if order==16 
	replace alpha2=round3 if order==17  
	replace alpha2=round3 if order==18 
	replace alpha2=round4 if order==19  
	replace alpha2=round2 if order==20 
	replace alpha2=round2 if order==21  
	replace alpha2=round4 if order==22 
	replace alpha2=round3 if order==23 

	generate alpha3=0

	replace alpha3=round3 if order==0 
	replace alpha3=round4 if order==1  
	replace alpha3=round2 if order==2 
	replace alpha3=round2 if order==3  
	replace alpha3=round4 if order==4 
	replace alpha3=round3 if order==5  
	replace alpha3=round3 if order==6 
	replace alpha3=round4 if order==7  
	replace alpha3=round2 if order==8 
	replace alpha3=round2 if order==9  
	replace alpha3=round4 if order==10 
	replace alpha3=round3 if order==11
	replace alpha3=round1 if order==12 
	replace alpha3=round1 if order==13  
	replace alpha3=round1 if order==14 
	replace alpha3=round1 if order==15  
	replace alpha3=round1 if order==16 
	replace alpha3=round1 if order==17  
	replace alpha3=round4 if order==18 
	replace alpha3=round3 if order==19  
	replace alpha3=round4 if order==20 
	replace alpha3=round3 if order==21  
	replace alpha3=round2 if order==22 
	replace alpha3=round2 if order==23

	generate alpha4=0

	replace alpha4=round4 if order==0 
	replace alpha4=round3 if order==1  
	replace alpha4=round4 if order==2 
	replace alpha4=round3 if order==3  
	replace alpha4=round2 if order==4 
	replace alpha4=round2 if order==5  
	replace alpha4=round4 if order==6 
	replace alpha4=round3 if order==7  
	replace alpha4=round4 if order==8 
	replace alpha4=round3 if order==9  
	replace alpha4=round2 if order==10 
	replace alpha4=round2 if order==11
	replace alpha4=round4 if order==12 
	replace alpha4=round3 if order==13  
	replace alpha4=round4 if order==14 
	replace alpha4=round3 if order==15  
	replace alpha4=round2 if order==16 
	replace alpha4=round2 if order==17  
	replace alpha4=round1 if order==18 
	replace alpha4=round1 if order==19  
	replace alpha4=round1 if order==20 
	replace alpha4=round1 if order==21  
	replace alpha4=round1 if order==22 
	replace alpha4=round1 if order==23
}
	
/*Creation of the variables seq1-seq4 for later use. This is an indicator variable for the order in which the particpants have seen the treatments*/
	
generate seq1 = 0
replace seq1=1 if order == 0
 
generate seq2 = 0
replace seq2=1 if order == 1

generate seq3 = 0
replace seq3=1 if order == 2
 
generate seq4 = 0
replace seq4=1 if order == 3

generate seq5 = 0
replace seq5=1 if order == 4
 
generate seq6 = 0
replace seq6=1 if order == 5

generate seq7 = 0
replace seq7=1 if order == 6
 
generate seq8 = 0
replace seq8=1 if order == 7
 
generate seq9 = 0
replace seq9=1 if order == 8
 
generate seq10 = 0
replace seq10=1 if order == 9

generate seq11 = 0
replace seq11=1 if order == 10
 
generate seq12 = 0
replace seq12=1 if order == 11

generate seq13 = 0
replace seq13=1 if order == 12
 
generate seq14 = 0
replace seq14=1 if order == 13

generate seq15 = 0
replace seq15=1 if order == 14
 
generate seq16 = 0
replace seq16=1 if order == 15

generate seq17 = 0
replace seq17=1 if order == 16
 
generate seq18 = 0
replace seq18=1 if order == 17

generate seq19 = 0
replace seq19=1 if order == 18
 
generate seq20 = 0
replace seq20=1 if order == 19

generate seq21 = 0
replace seq21=1 if order == 20
 
generate seq22 = 0
replace seq22=1 if order == 21

generate seq23 = 0
replace seq23=1 if order == 22
 
generate seq24 = 0
replace seq24=1 if order == 23

*****************************************
**Table 3: Summary of Experimental Data** 
*****************************************

summarize alpha1 alpha2 alpha3 alpha4, detail /* These 4 overviews provide the mean (Mean), 1st quartile (25%), median (50%) and the 3rd quartile (75%) amount bet on the risky lottery for alpha1-alpha4*/ 

/*The following summary statistics provide the number of observations on the boundaries 0 and 100. The output column "Obs" in the result tables corresponds to the values Min (0) and Max (100) in Table 3 */

summarize username if alpha1 == 0 
summarize username if alpha1 == 100

summarize username if alpha2 == 0 
summarize username if alpha2 == 100

summarize username if alpha3 == 0 
summarize username if alpha3 == 100

summarize username if alpha4 == 0 
summarize username if alpha4 == 100

***************************************************************
**Table 4: Treatment Effects: Wilcoxon signed-rank test (WSR)** 
***************************************************************

/*The column "Avg. change in DKK" is simply the difference in average amounts bet on the risky lottery as displayed in Table 3 (i.e. 71.7 - 67.5 = 4.2, 77.3 - 71.7 = 5.6, 76.5 - 77.3 = -0.8). Below you find the signed-rank. The reported value in Table 4 in column "p-value WSR" is denoted "Prob > |z|" in results.*/  

signrank alpha1=alpha2  /* Difference between treatment 0 and 1*/
signrank alpha2=alpha3	/* Difference between treatment 1 and 2*/	
signrank alpha3=alpha4 	/* Difference between treatment 2 and 3*/

***********************************************
**Data preperation for Tables 5 and following** 
***********************************************

/* The transformation creates for each participant 4 entries with decision equalying 1 to 4 for the different treatment levels*/ 

quietly{
	reshape long alpha, i(username) j(decision)

}
	
/*Data check to make sure the transformation is correct. The number of observations "Obs" and the average amount (Mean) invested in the risky lottery (alpha) conditional on treatment level 1 to 4 corresponds to the average values reported in Table 3*/

summarize alpha if decision==1 
summarize alpha if decision==2 
summarize alpha if decision==3 
summarize alpha if decision==4

/* In the following we generate the treatment variable C indicating the treatment dosis. It is 0, 0.1, 0.4 or 0.5. C is used in the later analsysis. Furthermore we generate treatment dumies DoS1, DoS2, UpS1 and UpS2 which will be used in the estimation of the Average Treatment Effects reported in Table 5*/

quietly{

	generate C = 0
	replace C = 0.1 if decision==2
	replace C = 0.4 if decision==3
	replace C = 0.5 if decision==4

	generate DoS1=1 
	replace DoS1=0 if decision==2
	replace DoS1=0 if decision==3
	replace DoS1=0 if decision==4 

	generate DoS2=1 
	replace DoS2=0 if decision==1
	replace DoS2=0 if decision==3
	replace DoS2=0 if decision==4 

	generate UpS1=1 
	replace UpS1=0 if decision==2
	replace UpS1=0 if decision==1
	replace UpS1=0 if decision==4 

	generate UpS2=1 
	replace UpS2=0 if decision==2
	replace UpS2=0 if decision==3
	replace UpS2=0 if decision==1 

}

****************************************************************
**Table 5: Average Treatment Effects: Tobit Regression Estimates 
****************************************************************

/*The output tables contain the data for all the results reported in Table 5:

Treatment level 1	= Dos2
Treatment level 2	= Ups1
Treatment level 3	= Ups2
Constant	= _cons
Sample size	= Number of obs
Number of clusters	= Indicated above the result table
Log likelihood	= Log pseudolikelihood*/

/*Specification (1) in Table 5*/

tobit alpha DoS2 UpS1 UpS2, ll(0) ul(100) vce(cl username) 

/* Specification (2) in Table 5*/ 
 
tobit alpha DoS2 UpS1 UpS2 seq2 seq3 seq4 seq5 seq6 seq7 seq8 seq9 seq10 seq11 seq12 seq13 seq14 seq15 seq16 seq17 seq18 seq19 seq20 seq21 seq22 seq23 seq24, ll(0) ul(100) vce(cl username)

/* Specification (3) in Table 5*/ 

tobit alpha DoS2 UpS1 UpS2, ll(0) ul(100) 


*************************************************************
**Table 6: Structural Equations: Tobit Regression Estimates**
*************************************************************

/* In this part we estimate everything in relation to Table 6 in section 3.3 of the paper.*/   

/* Structural Estimation Model */

/*CARA Utility Function: the following variables are used to estimate equation 8 with CARA utility*/

quietly{
	generate gPayoffRatio = (1.1+C)/(0.4+C)	        /* Payoff ratio (good state) = Payoff of risky lottery in good state devided by payoff from the risk free asset in each treatment */

	generate bPayoffRatio = (0.4+C)/(0.1+C)			/* Payoff ratio (bad state) = Payoff of risky lottery in bad state devided by payoff from the risk free asset in each treatment*/

	generate RatioCont = gPayoffRatio / bPayoffRatio	/* ratio of the payoff ratios */

	generate lnRatioCont = ln(RatioCont)				/* natural logarithm of this ratio used used in equation 8 on page 23 */
}

/*CARA-Tobit regression model (censored at 0 and 100): results of this regression are reported in specification 1 ("Amount bet"") of Table 6 on page 50*/

tobit alpha lnRatioCont, ll(0) ul(100) vce(cl username)

/* The variables in the table (Table 6) and their corresponding counterparts in the regression output are:

Log ratio of relative payoffs	= lnRatioCont
Constant	= _cons
Sample size	= Number of obs
Number of clusters	= 473	
Log likelihood	= Log pseudolikelihood

The estimates of the salience and risk aversion parameter reported at the bottom of Table 6 is calculated on the basis of the relations reported immediately after equation (8): ρ = ln(3.5)/a and γ = bρ */

/*CRRA-Tobit regression model (censored at 0 and 0.887): results of this regression are reported in specification 2 ("Log relative wealth"") of Table 6

We can change regression equation (8) into a CRRA-Tobit regression model (censored at 0 and 0.887) by replacing y with outcome ln [c_{g,i,j}/c_{b,i,j}] on the left-hand side of equation (8).*/

quietly{
	generate OptWg= 100+(1.1-0.4)*alpha  	/* wealth consequence of choosing alpha in the good state g */ 

	generate OptWb= 100+(0.1-0.4)*alpha		/* wealth consequence of choosing alpha in the bad state g */

	generate lnRatioW = ln(OptWg/OptWb)		/* natural logarithm of this ratio used used on the left hand-side in equation 8 on page 23 */
}
tobit lnRatioW lnRatioCont, ll(0) ul(0.887) vce(cl username)

/* The variables in the table (Table 6) and their corresponding counterparts in the regression output are:

Log ratio of relative payoffs	= lnRatioCont
Constant	= _cons
Sample size	= Number of obs
Number of clusters	= 473	
Log likelihood	= Log pseudolikelihood

The estimates of the salience (γ) and risk aversion parameter (ρ) reported at the bottom of Table 6 is calculated on the basis of the relations reported immediately after equation (8): ρ = ln(3.5)/a and γ = bρ */

********************************
**Estimates: Section 4.1
********************************

/* To assess the extent to which Benartzi and Thaler's model can explain our observations, we rewrite quation (13) on page 29 as a modification of our structural model (7): 

Our estimation uses the CRRA function v(c_s − c₀) = (c_s − c₀)(1−ρ) with 0 < ρ < 1, as is the custom in the gain domain of Prospect Theory.*/

/*quietly{*/

	generate OptRg= (0.4+C)*(100-alpha)+(1.1+C)*alpha  	/* this is the difference between the wealth consequence of choosing alpha in the good state (c_g) minus the reference point (c₀ = (e-m)):  c_g − c₀ */

	generate OptRb= (0.4+C)*(100-alpha)+(0.1+C)*alpha 	/* this is the difference between the wealth consequence of choosing alpha in the bad state (c_b) minus the reference point (c₀ = (e-m)):  c_b − c₀ */

	generate lnRatioR = ln(OptRg/OptRb) 				/* the natuaral logarithm of the ratio of OptRg and OptRb */ 
			
/*}*/

/* To allow for variable censoring across treatments we create the following max ratios indicating the maximum OptRg if everything is invested in the risky asset. */

generate max=ln(110/10)

replace max=ln(120/20) if decision == 2

replace max=ln(150/50) if decision == 3

replace max=ln(160/60) if decision == 4

generate depvarU=lnRatioR if decision==1 & lnRatioR<max | decision==2 & lnRatioR<max | decision==3 & lnRatioR<max | decision==4 & lnRatioR<max

generate depvarL=lnRatioR if lnRatioR>0 

intreg depvarL depvarU, vce(cl username)

/* We are interested in the estimate for the constant a in the Tobit model with variable censoring across treatments:

a = _cons

The estimate a = 1.399 is reported right underneath equation 15*/

log close
 